package com.itheima.controller.user;


import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.Result;
import com.itheima.pojo.Setmeal;
import com.itheima.service.UserSetmealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping ("/setmeal")
@Api(tags = "用户端套餐管理")
public class UserSetmealController {
    @Autowired
    private UserSetmealService userSetmealService ;

    /**
     * 获取所有套餐信息
     *
     * @return
     */
    @PostMapping("/getSetmeal")
    @ApiOperation("获取所有套餐信息")
    public Result getSetmeal() {
        try {
            log.info("获取所有套餐信息");
            List<Setmeal> setmeal = userSetmealService.usergetSetmeal();
            return new Result(true, MessageConstant.GET_SETMEAL_LIST_SUCCESS, setmeal);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.GET_SETMEAL_LIST_FAIL);
        }
    }

    /**
     *根据套餐id查询套餐详情
     *
     *
     */
    @PostMapping ("/findById")
    @ApiOperation("根据套餐id查询套餐详情")
    public Result findById(Integer id){
        try {
            log.info("根据套餐id查询套餐详情");
            Setmeal setmeal = userSetmealService.findById(id);
            return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS, setmeal);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }








}
